﻿@using System.Text
@using OA.Model
@using OA.AspNetCore.Html
@using OA.Core.Model
@using OA.Core.Helper

@model OA.Model.Position
@{ 
    BaseConfig baseConfig = ViewBag.BaseConfig;
    var positionLevels = new List<ListItem>();
    if (baseConfig != null && !string.IsNullOrWhiteSpace(baseConfig.PositionLevel))
    {
        positionLevels = baseConfig.PositionLevel.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(m => new ListItem() { Value = m, Text = m }).ToList();
    }
    if (positionLevels == null)
    {
        positionLevels = new List<ListItem>();
    }
}
<div class="layui-my-content">
    <div class="myForm">
        @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
        {
            @Html.AntiForgeryToken()
            <div class="layui-form-item">
                @Html.LabelFor(model => model.DepartmentID, new { @class = "layui-form-label" })
                <div class="layui-input-block MyDepartments">
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.Name, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.HiddenFor(model => model.ID)
                    @Html.MyEditorFor(model => model.Name)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.Level, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.Level, positionLevels)
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.IsVirtual, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.MyEditorFor(model => model.IsVirtual)
                </div>
            </div>            

        <div class="layui-form-item myRegion">
            @Html.LabelFor(model => model.Sort, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.MyEditorFor(model => model.Sort)
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="submit" value="提 交" lay-submit="" lay-filter="OAForm" class="layui-btn mySubmit" />
            </div>
        </div>
    }
    </div>
</div>
<script type="text/javascript" src="/Member/Home/GetDepartmentAndPosition"></script>
<script type="text/javascript" src="@ViewBag.OssUrl/front/js/department.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layedit', 'autocomplete', 'element', 'layer', 'laydate'], function () {
        form = layui.form;
        layer = layui.layer;
        element = layui.element;
        laydate = layui.laydate;
        form.on('select(Department)', function (data) {
            InitDepartment($(".MyDepartments"), data.value);
            form.render('select');
        });
    });
    InitDepartment($(".MyDepartments"), @Model.DepartmentID);
</script>
